package com.flipdf2;

import java.util.LinkedList;
import java.util.List;

import com.flipdf2.event.DocumentEvent;
import com.flipdf2.event.DocumentListener;

public class Document {
	private List<Page> pageList;
	private List<DocumentListener> listenerList;

	public Document() {
		this.pageList = new LinkedList<Page>();
		this.listenerList = new LinkedList<DocumentListener>();
	}

	public void addPage(Page page) {
		this.pageList.add(page);
		fireValueChanged();
	}

	public void removePage(Page page) {
		this.pageList.remove(page);
		fireValueChanged();
	}

	public Page getPage(int i) {
		return this.pageList.get(i);
	}

	public int getPageCount() {
		return this.pageList.size();
	}

	private void fireValueChanged() {
		DocumentEvent e = new DocumentEvent(this);
		for (DocumentListener listener : listenerList) {
			listener.valueChanged(e);
		}
	}
}
